From 8a14c306d809d9a3e26b2824bdf34318c2466888 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 23 Jul 2014 09:09:33 -0700 Subject: [PATCH] Fix `cargo test` with a dylib when run twice The filename of the test for a dylib wasn't being calcuated correctly, so when freshness was copying data over it ended up copying the same file twice. --- src/cargo/ops/cargo_rustc/context.rs | 19 +++++------- tests/test_cargo_test.rs | 45 +++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 083c12bec..9a113e41b 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -175,20 +175,17 @@ impl<'a, 'b> Context<'a, 'b> { let stem = target.file_stem(); let mut ret = Vec::new(); - if target.is_dylib() { - let (prefix, suffix) = self.dylib(target.get_profile().is_plugin()); - ret.push(format!("{}{}{}", prefix, stem, suffix)); - } - if target.is_rlib() { - if target.get_profile().is_test() { - ret.push(format!("{}{}", stem, self.target_exe)); - } else { + if target.is_bin() || target.get_profile().is_test() { + ret.push(format!("{}{}", stem, self.target_exe)); + } else { + if target.is_dylib() { + let (prefix, suffix) = self.dylib(target.get_profile().is_plugin()); + ret.push(format!("{}{}{}", prefix, stem, suffix)); + } + if target.is_rlib() { ret.push(format!("lib{}.rlib", stem)); } } - if target.is_bin() { - ret.push(format!("{}{}", stem, self.target_exe)); - } assert!(ret.len() > 0); return ret; } diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index 1a0ff9c94..16eb46dda 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -2,7 +2,7 @@ use std::path; use std::str; use support::{project, execs, basic_bin_manifest, basic_lib_manifest}; -use support::{COMPILING, cargo_dir, ResultTest}; +use support::{COMPILING, cargo_dir, ResultTest, FRESH}; use hamcrest::{assert_that, existing_file}; use cargo::util::process; @@ -516,3 +516,46 @@ test!(bin_there_for_integration { assert!(output.contains("main_test ... ok"), "no main_test\n{}", output); assert!(output.contains("test_test ... ok"), "no test_test\n{}", output); }) + +test!(test_dylib { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [[lib]] + name = "foo" + crate_type = ["dylib"] + "#) + .file("src/lib.rs", " + #[test] + fn foo() {} + "); + + assert_that(p.cargo_process("cargo-test"), + execs().with_status(0) + .with_stdout(format!("\ +{compiling} foo v0.0.1 (file:{dir}) + +running 1 test +test foo ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n\n\ + ", + compiling = COMPILING, + dir = p.root().display()).as_slice())); + assert_that(p.process(cargo_dir().join("cargo-test")), + execs().with_status(0) + .with_stdout(format!("\ +{fresh} foo v0.0.1 (file:{dir}) + +running 1 test +test foo ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n\n\ + ", + fresh = FRESH, + dir = p.root().display()).as_slice())); +}) -- 2.30.2